package com.controllers;

import com.services.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.SystemEnvironmentPropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.socket.TextMessage;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2016/5/18 0018.
 */
@Controller("indexController")
@RequestMapping("/index")
public class IndexController {

    //@Autowired
    //private IndexService indexService;
    public IndexController() {
        System.out.println("初始化完成！！！！！！！！！！！！！！！！！！！！！");
    }

    @RequestMapping(method = {RequestMethod.GET,RequestMethod.HEAD})
    public String index(ModelMap model,@RequestParam(required = false)String code){
        //System.out.println( indexService.getCode());
        return "index";
    }

    @ResponseBody
    @RequestMapping(value = "sendMessage",method = {RequestMethod.GET,RequestMethod.HEAD})
    public String sendMessage(String message,ModelMap modelMap,HttpServletRequest request){
        System.out.println(request);
        WebSocketConfig.webSocketHander.sendMessageToUsers(new TextMessage(message));
        return "发送成功";
    }
}
